﻿namespace Pyramid.Hardware
{
    using System;

    public class DFlipFlop
        : FlipFlopBase
    {
        private ILine data;
        private ILine clock;

        public DFlipFlop(ILine data, ILine clock)
        {
            this.data = data;
            this.clock = clock;

            this.clock.SignalChange += new EventHandler<SignalChangeEventArgs>(Clock_SignalChange);
        }

        private void Clock_SignalChange(object sender, SignalChangeEventArgs e)
        {
            //If clock has gone high (rising edge of clock pulse)
            if (this.clock.Signal == Trivalent.True)
            {
                //Set output to match the data line
                SetOutput(this.data.Signal);
            }
        }
    }
}
